<?php
namespace app\admin\controller;

class TableList extends Father
{
    //获取列控制
    public function index()
    {
        if ($this->request->isPost()) {
            $limit = input('limit');
            $page = input('page');

            $list = db('adm_table_list')
            ->field("adm_table_list.id,table_field,auth_name , adm_table_list.auth_id,table_title")
            ->join("adm_auth","adm_table_list.auth_id=adm_auth.auth_id")
            ->paginate($limit)->toArray();

            return json(['code'=>0,'msg'=>'','count'=>$list['total'] ,'data'=>$list['data']]);
        }else{
            return $this->fetch();
        }
    }

    public function edit(){
        if (request()->isPost()) {
            $id = input('post.id');
            $table_field = input('post.table_field');
            $table_title = input('post.table_title');

            $id = db('adm_table_list')->where('id',$id)->update(['table_field'=>$table_field,'table_title'=>$table_title]);

            if($id){
                return json(['code'=>200]);
            }else{
                return json(['code'=>0]);
            }
        }else{
            $this->assign('infodata',db('adm_table_list')->where('id',input('get.id'))->find() );
            return $this->fetch();
        }
    }
    public function add(){
        if (request()->isPost()) {
            $auth_id = input('post.auth_id');
            $table_field = input('post.table_field');
            $table_title = input('post.table_title');

            $id = db('adm_table_list')->insertGetId(['auth_id'=>$auth_id,'table_field'=>$table_field,'table_title'=>$table_title]);

            return json(['code'=>200]);
        }else{

            $adm_auth = db("adm_auth")
            ->alias("a")
            ->field("a.auth_name,a.auth_id")
            ->where('is_menu',1)
            ->where('auth_c_a','<>','顶级路由')
            ->select();

            $this->assign('adm_auth',$adm_auth);
            return $this->fetch();
        }
    }
    public function del(){
        if (request()->isPost()) {
            $id = input('post.id');

            $id = db('adm_table_list')->where('id',$id)->delete();

            if($id){
                return json(['code'=>200]);
            }else{
                return json(['code'=>0]);
            }
        }
    }
    //列控制
    public function ListController()
    {
        if ($this->request->isPost()) {

            $roleId = trim(input('post.role_id'));

            if (!is_numeric($roleId)) {

                return json(['code' =>0, 'msg' => '参数错误！~请重试']);
            }


        }
    }
}
